﻿using DDD.Domain;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GoodsModule.Domain.GoodsCategoryAggregate
{
    public record GoodsCategoryId(int Id);

    [Comment("商品分类")]
    [Table("WbGoodsCategory")]
    public class GoodsCategory : Entity<int>, IAggregateRoot
    {
        [Comment("标题")]
        [Required]
        [StringLength(20)]
        public string Title { get; private set; } = string.Empty;

        [Comment("排序")]
        [Required]
        public int Sort { get; private set; } = 1000;

        private GoodsCategory() { }

        public GoodsCategory(string title, int sort = 1000)
        {
            Title = title;
            Sort = sort;

            //this.AddDomainEvent(this);
        }

        public override void Delete()
        {
            IsDeleted = true;
            //发布删除事件，通知对应商品删除下架
            AddDomainEvent(new GoodsCategoryDomainEvents.GoodsCategoryDeletedDomainEvent(this));
        }
    }
}
